package javase.student_information_system;

import java.util.ArrayList;
import java.util.Scanner;

class StudentSystem {
    public static void main(String[] args) {
        Student stu1 = new Student("20180302","叶孤城",23,"护理一班");
        Student stu2 = new Student("20180303","陈峰",23,"推拿二班");
        Student stu3 = new Student("20180304","高聪",26,"中药学四班");
        Student stu4 = new Student("20180305","李昌",26,"神经科二班");
        ArrayList<Student> arrayList = new ArrayList<>();
        arrayList.add(stu1);
        arrayList.add(stu2);
        arrayList.add(stu3);
        arrayList.add(stu4);
        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.print("请输入学生id: ");
            String stuId = sc.next();
            Student student = selectId(arrayList, stuId);
            if (student != null)
                System.out.println(student);
            else
                System.out.println("学生id不存在");
        }
    }

    /**
     * 按照id返回对象信息
     */
    public static Student selectId(ArrayList<Student> arrayList,String id){
        for (int i = 0; i < arrayList.size(); i++) {
            if(arrayList.get(i).getStudentId().equals(id)){
                //找到了指定对象
                return arrayList.get(i);
            }
        }
        return null;
    }
}
